/**
 * 有三个线程，线程名称分别为：a，b，c。
 * 每个线程打印自己的名称。
 * 需要让他们同时启动，并按 c，b，a的顺序打印
 */
public class Main {

    public static void main(String[] args) {
        Object o1 = new Object();

        Object o2 = new Object();

        Thread a = new Thread(() -> {
            synchronized (o1) {
                try {
                    o1.wait();// 线程 a等待 o1锁的释放
                    System.out.println(Thread.currentThread().getName());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"线程a");
        Thread b = new Thread(() -> {
            synchronized (o2) {
                try {
                    o2.wait();
                    System.out.println(Thread.currentThread().getName());
                    synchronized (o1) {
                        o1.notify();
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"线程b");
        Thread c = new Thread(() -> {
            System.out.println(Thread.currentThread().getName());
            synchronized (o2){
                o2.notify();
            }
        },"线程c");
        a.start();
        b.start();
        c.start();
    }
}
